<?php

/**
 * Calendar controller
 *
 * Calendar controller in application
 *
 * PHP Version: 1.2.3
 *
 * @author Johari <joharijumali@gmail.com>
 */

/**
 * Admin Calendar class
 *
 * Generate Leave Calendar
 *
 * @author Johari <joharijumali@gmail.com>
 */

class Administrator_Calendar_Controller extends Base_Controller
{

    public $restful = true;

	/**
     * Function get_main
	 *
	 * @return get_main.
     */	
	public function get_main()
	{
		$data['listHoliday'] = Data_Calendar_Holiday::listHoliday();

		return View::make('administrator.calendar.main', $data);
	}
	
	/**
     * Function post_holiday
	 *
	 * @return post_holiday.
     */
	public function post_holiday()
	{
		$input = Input::get();

		$rules = array(
            'wdh_hol_name' => 'required|unique:wt_data_holiday,wdh_hol_name',
			'wdh_hol_date' => 'required|uniquefor:wt_data_holiday,wdh_hol_date',
        );
        
        $messages = array(
            'unique' => 'Cuti Telah Wujud',
            'uniquefor' => 'Tarikh Telah Wujud',
        );
        
        $validate = Validator::make($input, $rules, $messages);

        if ($validate->fails()) {
            return json_encode($validate->errors);
        }

        Data_Calendar_Holiday::addHoliday($input);

        return json_encode(Data_Calendar_Holiday::listHoliday());
	}
	
	public function post_editHoliday()
	{
        $input = Input::get();
				
		$rules = array(
            'wdh_hol_name' => 'required|unique:wt_data_holiday,wdh_hol_name,'.$input['wdh_id'].',wdh_id',
			'wdh_hol_date' => 'required|uniquefor:wt_data_holiday,wdh_hol_date,'.$input['wdh_id'].',wdh_id',
        );
        
        $messages = array(
            'unique' => 'Cuti Telah Wujud',
            'uniquefor' => 'Tarikh Telah Wujud',
        );
        
        $validation = Validator::make($input, $rules, $messages);

		if ($validation->fails()) {
			return json_encode($validation->errors);
		}
														
		Data_Calendar_Holiday::editHoliday($input);
				
        return json_encode(Data_Calendar_Holiday::listHoliday());
    }
	
	/**
     * Function get_holiday
	 *
	 * @return get_holiday.
     */
	public function get_holiday()
	{
		$month = Input::get('month');
		$year = Input::get('year');

		return json_encode(Data_Calendar_Holiday::holiday($month, $year));
	}
	
	/**
     * Function get_holidayData
	 *
	 * @return get_holidayData.
     */
	public function get_holidayData()
	{
		return json_encode(Data_Calendar_Holiday::holidayData(Input::get('id')));
	}

	/**
     * Function post_deleteHoliday
	 *
	 * @return post_deleteHoliday.
     */
	public function post_deleteHoliday()
	{
        $input = Input::get();

        Data_Calendar_Holiday::deleteHol($input);

		return json_encode(Data_Calendar_Holiday::listHoliday());
	}

}

?>